package com.winning.sjzc.common.utils;

import com.winning.sjzc.common.entity.vo.JgTreeEntity;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName : JgTreeUtil
 * @Description : 递归构造机构树型结构
 * @Author : zhanglei
 * @Date : 2019/6/11 17:16
 **/
public class JgTreeUtil {
    public List<JgTreeEntity> jgCommon;
    public List<Object> list = new ArrayList<Object>();

    public List<Object> jgTreeList(List<JgTreeEntity> jgList,String jgbm){
        this.jgCommon = jgList;
        for (JgTreeEntity jte : jgList) {
            Map<String,Object> mapArr = new LinkedHashMap<String, Object>();
            if(jgbm.equals(jte.getSjjgbm())){
                mapArr.put("id", jte.getJgbm());
                mapArr.put("name", jte.getJgmc());
                mapArr.put("pId", jte.getSjjgbm());
                mapArr.put("jglb", jte.getJglb());
                list.add(mapArr);
                list.addAll(jgChild(jte.getJgbm()));
            }
        }
        return list;
    }

    public List<?> jgChild(String jgbm){
        List<Object> lists = new ArrayList<Object>();
        for(JgTreeEntity a:jgCommon){
            Map<String,Object> childArray = new LinkedHashMap<String, Object>();
            if(a.getSjjgbm()!=null && a.getSjjgbm().equals(jgbm)){
                childArray.put("id", a.getJgbm());
                childArray.put("name", a.getJgmc());
                childArray.put("pId", a.getSjjgbm());
                childArray.put("jglb", a.getJglb());
                lists.add(childArray);
                lists.addAll(jgChild(a.getJgbm()));
            }
        }
        return lists;
    }
}









